#include "stdafx.h"
#include "script_editor_new_script.h"

ScriptEditorNewScript::ScriptEditorNewScript(QWidget* pwgt) 
	: QDialog(pwgt, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
{
	ui.setupUi(this);
	connect(ui.bAccept, SIGNAL(clicked), this, SLOT(on_bAccept_clicked));
	connect(ui.bReject, SIGNAL(clicked), this, SLOT(on_bReject_clicked));
}

void ScriptEditorNewScript::setData(const QString &_name, const QString &_description) {
	ui.txtName->setText(_name);
	ui.teDescription->setPlainText(_description);
}
QString ScriptEditorNewScript::getName(){
	return ui.txtName->text();
}

QString ScriptEditorNewScript::getDescription(){
	return ui.teDescription->toPlainText();
}

void ScriptEditorNewScript::on_bAccept_clicked(){
	if (ui.txtName->text().isEmpty()){
		QMessageBox::critical(0, tr("Error"), tr("Empty name is not valid!"), QMessageBox::Ok);	
		return;
	}
	accept();
}

void ScriptEditorNewScript::on_bReject_clicked(){
	int result = QMessageBox::information(this, "Close", 
		"Close the form? any unsaved data will be lost", 
		QMessageBox::Yes | QMessageBox::Default, 
		QMessageBox::No, 
		QMessageBox::Cancel | QMessageBox::Escape); 
	if (result == QMessageBox::Yes) 
		reject();
}
